package user.zc.excel.render;

import user.zc.excel.data.info.ICell;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;

class StyleRender implements ICreate<XSSFCellStyle, ICell.CellInfo>{

    private XSSFCell xssfCell;
    public StyleRender(XSSFCell xssfCell){
        this.xssfCell = xssfCell;
    }
    @Override
    public XSSFCellStyle next() {
        return null;
    }

    @Override
    public void draw(ICell.CellInfo data) {
        XSSFCellStyle style = xssfCell.getRow().getSheet().getWorkbook().createCellStyle();
        XSSFFont font = xssfCell.getRow().getSheet().getWorkbook().createFont();
        font.setBold(data.getStyleInfo().getFont().isBold());
        font.setColor(data.getStyleInfo().getFont().getColor());
        font.setFontHeightInPoints(data.getStyleInfo().getFont().getHeight());
        font.setFontName(data.getStyleInfo().getFont().getName());
        style.setFont(font);
        style.setAlignment(data.getStyleInfo().getAlignment());
        style.setVerticalAlignment((short)1);
        style.setFillForegroundColor(data.getStyleInfo().getColor());
        style.setFillPattern((short)1);
        style.setBorderBottom((short)1);
        style.setBorderLeft((short)1);
        style.setBorderTop((short)1);
        style.setBorderRight((short)1);
        style.setWrapText(data.getStyleInfo().isWrapText()); // 设置文本换行
        xssfCell.setCellStyle(style);
    }
}
